package top.korori.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import top.korori.common.model.Result;
import top.korori.entity.req.SvUserAvatarReq;
import top.korori.entity.req.SvUserEditReq;
import top.korori.entity.res.SvEditUserInfoRes;
import top.korori.entity.res.SvUserAreaTreeRes;
import top.korori.entity.res.SvUserInfoRes;
import top.korori.service.ISvUserAreaService;
import top.korori.service.ISvUserService;

import java.util.List;

/**
 * 短视频前台用户 前端控制器
 *
 * @author korori
 */
@Api(tags = "用户信息接口")
@RestController
@RequestMapping("/sv/user")
public class SvUserController {

    @Autowired
    private ISvUserAreaService svUserAreaService;

    @Autowired
    private ISvUserService svUserService;

    @ApiOperation("获取用户地址选择数据")
    @GetMapping("/areaTree")
    public Result<List<SvUserAreaTreeRes>> areaTree() {
        List<SvUserAreaTreeRes> tree = svUserAreaService.tree();
        return Result.ok(tree);
    }

    @ApiOperation("获取要修改用户的信息")
    @GetMapping("/getEditInfo")
    public Result<SvEditUserInfoRes> getEditInfo() {
        SvEditUserInfoRes svEditUserInfoRes = svUserService.getEditInfo();
        return Result.ok(svEditUserInfoRes);
    }


    @ApiOperation("修改用户信息")
    @PutMapping("/editInfo")
    public Result<Void> editInfo(@RequestBody @Validated SvUserEditReq svUserEditReq) {
        svUserService.editInfo(svUserEditReq);
        return Result.ok();
    }

    @ApiOperation(value = "Base64头像上传", notes = "仅支持png,jpg,jpeg类型图片")
    @PostMapping("/uploadAvatar")
    public Result<Void> uploadAvatar(@RequestBody @Validated SvUserAvatarReq svUserAvatarReq) {
        svUserService.uploadAvatar(svUserAvatarReq.getBase64());
        return Result.ok();
    }

    @ApiOperation(value = "文件头像上传",notes = "仅支持png,jpg,jpeg类型图片")
    @PostMapping("/uploadAvatarFile")
    public Result<Void> uploadAvatarFile(@RequestPart MultipartFile file){
        svUserService.uploadAvatarFile(file);
        return Result.ok();
    }

    @ApiOperation("获取当前登录用户信息")
    @GetMapping("/getLoginInfo")
    public Result<SvUserInfoRes> getLoginInfo() {
        SvUserInfoRes svUserInfoRes = svUserService.getLoginInfo();
        return Result.ok(svUserInfoRes);
    }


}




















